#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
 
#import requests as req
#import re
import time
import argparse

raw = """
Title: %s
Date: %s
Slug: %s
Tags: %s
Description:
Summary: 
"""

def dumpUsage():
	print """
	$ sniky.py -t "Title of new post" -s "Slug"
	"""
def main():
	raw = "Title:%s\n"

	if(args.slug is None):
		slug = args.title
	else:
		slug = args.slug
	raw = raw % (args.title)

	date = time.strftime("%Y-%m-%d")	
	raw = raw + "Date: %s\nSlug: %s\n" % (date, slug)

	tags = ""
	if(args.tags is not None):
		#tags = args.tags.join(',')
		tags = args.tags[1:-1]
	raw = raw + "Tags: %s\nDescription: \nSummary: \nKeywords: \n" % tags

	post = open('%s-%s.md' % (date, slug), 'wb+')
	post.write(raw)
	post.close()

if __name__ == '__main__':
	parser = argparse.ArgumentParser()
	parser.add_argument('title', help="Title of the post")
	parser.add_argument('-s', dest='slug', help="Slug as post file name & url")
	parser.add_argument('-tags', '--tags', dest='tags', help="Tags of the format: [tag1, tag2,...]")

	args = parser.parse_args()
	main()
